package com.hue.springbooteasyexcel.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hue.springbooteasyexcel.dao.UserMapper;
import com.hue.springbooteasyexcel.domain.TbUser;
import com.hue.springbooteasyexcel.domain.UserRelation;
import com.hue.springbooteasyexcel.listener.ExcelListener;
import com.hue.springbooteasyexcel.service.UserRelationService;
import com.hue.springbooteasyexcel.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: 姚凤桥
 * @Date: 2022/4/12 14:34
 * @Description:
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, TbUser> implements UserService {
    @Autowired
    private UserRelationService userRelationService;

    @Override
    public void importUser(MultipartFile file) {

    }

    @Override
    public void add(TbUser user) {
        //排除name为用户+数字的人
        String account = user.getAccount();
        String reg = "用户[0-9]+";
        if (account.matches(reg)) {
            return;
        }
        //保存用户
        save(user);

        UserRelation relation1 = new UserRelation();
        relation1.setFromId(user.getId());
        relation1.setToId(1L);
        userRelationService.save(relation1);

        if (Math.random() < 0.5) {
            UserRelation relation = new UserRelation();
            relation.setFromId(1L);
            relation.setToId(user.getId());
            userRelationService.save(relation);
        }
    }
}
